package br.com.util;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;



@XmlType
class Ide{
	private int nNF;
	private Date dEmi;
	
	@XmlElement(name="nNF",required=true)
	public int getNnf(){return nNF;}
	
	@XmlElement(name="dEmi",nillable=false,required=true)
	public Date getDemi(){return dEmi;}
	
	public void setNnf(int xs){
		nNF=xs;
	}
	
	public void setDemi(Date ds){
		dEmi=ds;
	}
	
}

@XmlType
class EnderDest{
	private String xLgr, nro, xBairro, xMun, UF,CEP,xPais;
	
	@XmlElement(name="xLgr",required=true,nillable=false)
	public String getxLgr() {
		return xLgr;
	}

	public void setxLgr(String xLgr) {
		this.xLgr = xLgr;
	}
	
	@XmlElement(name="nro",required=true,nillable=false)
	public String getNro() {
		return nro;
	}

	public void setNro(String nro) {
		this.nro = nro;
	}

	@XmlElement(name="xBairro",required=true,nillable=false)
	public String getxBairro() {
		return xBairro;
	}

	public void setxBairro(String xBairro) {
		this.xBairro = xBairro;
	}

	@XmlElement(name="xMun",required=true,nillable=false)
	public String getxMun() {
		return xMun;
	}

	public void setxMun(String xMun) {
		this.xMun = xMun;
	}

	@XmlElement(name="UF",required=true,nillable=false)
	public String getUF() {
		return UF;
	}

	public void setUF(String uF) {
		UF = uF;
	}

	@XmlElement(name="CEP",required=true,nillable=false)
	public String getCEP() {
		return CEP;
	}

	public void setCEP(String cEP) {
		CEP = cEP;
	}

	@XmlElement(name="xPais",required=true,nillable=false)
	public String getxPais() {
		return xPais;
	}

	public void setxPais(String xPais) {
		this.xPais = xPais;
	}
	
}

@XmlType
class Dest{
	private String cnpj,xNome,ie;
	private EnderDest enderDest;
	
	@XmlElement(name="CNPJ",required=true,nillable=false)
	public String getCnpj() {
		return cnpj;
	}

	public void setCnpj(String cnpj) {
		this.cnpj = cnpj;
	}

	@XmlElement(name="xNome",required=true,nillable=false)
	public String getxNome() {
		return xNome;
	}

	public void setxNome(String xNome) {
		this.xNome = xNome;
	}

	@XmlElement(name="IE",nillable=false,required=true)
	public String getIe() {
		return ie;
	}

	public void setIe(String ie) {
		this.ie = ie;
	}

	@XmlElement(name="enderDest",required=true,nillable=false)
	public EnderDest getEnderDest() {
		return enderDest;
	}

	public void setEnderDest(EnderDest enderDest) {
		this.enderDest = enderDest;
	}
	
}

@XmlType
class Prod{
	private String cProd,xProd,ucom;
	private double qcom,vuncom,vprod;
	private int cfop;
	
	@XmlElement(name="cProd",required=true)
	public String getcProd() {
		return cProd;
	}
	public void setcProd(String cProd) {
		this.cProd = cProd;
	}
	@XmlElement(name="xProd",required=true,nillable=false)
	public String getxProd() {
		return xProd;
	}
	public void setxProd(String xProd) {
		this.xProd = xProd;
	}
	@XmlElement(name="uCom",required=true,nillable=false)
	public String getUcom() {
		return ucom;
	}
	public void setUcom(String ucom) {
		this.ucom = ucom;
	}
	@XmlElement(name="qCom",required=true)
	public double getQcom() {
		return qcom;
	}
	public void setQcom(double qcom) {
		this.qcom = qcom;
	}
	@XmlElement(name="vUnCom",required=true)
	public double getVuncom() {
		return vuncom;
	}
	public void setVuncom(double vuncom) {
		this.vuncom = vuncom;
	}
	@XmlElement(name="vProd",required=true)
	public double getVprod() {
		return vprod;
	}
	public void setVprod(double vprod) {
		this.vprod = vprod;
	}
	@XmlElement(name="CFOP",required=true)
	public int getCfop() {
		return cfop;
	}
	public void setCfop(int cfop) {
		this.cfop = cfop;
	}
	
}

@XmlType
class Det{
	private int nitem;
	private Prod prod;
	
	@XmlAttribute(name="nItem",required=true)
	public int getNitem() {
		return nitem;
	}
	public void setNitem(int nitem) {
		this.nitem = nitem;
	}
	@XmlElement(name="prod",required=true,nillable=false)
	public Prod getProd() {
		return prod;
	}
	public void setProd(Prod prod) {
		this.prod = prod;
	}
	
	
	
}

@XmlType
class Vol{
	private int qVol;
	private String esp;
	private double pesoL,pesoB;
	
	@XmlElement(name="qVol",required=true)
	public int getqVol() {
		return qVol;
	}
	public void setqVol(int qVol) {
		this.qVol = qVol;
	}
	@XmlElement(name="esp",required=true)
	public String getEsp() {
		return esp;
	}
	public void setEsp(String esp) {
		this.esp = esp;
	}
	@XmlElement(name="pesoL",required=true)
	public double getPesoL() {
		return pesoL;
	}
	public void setPesoL(double pesoL) {
		this.pesoL = pesoL;
	}
	@XmlElement(name="pesoB",required=true)
	public double getPesoB() {
		return pesoB;
	}
	public void setPesoB(double pesoB) {
		this.pesoB = pesoB;
	}
}

@XmlType
class Transp{
	private Vol vol;
	
	@XmlElement(name="vol",required=true,nillable=false)
	public Vol getVol() {
		return vol;
	}
	public void setVol(Vol vol) {
		this.vol = vol;
	}
}

@XmlType
class ICMSTot{
	private double vnf;
	
	@XmlElement(name="vNF",required=true)
	public double getVnf() {
		return vnf;
	}

	public void setVnf(double vnf) {
		this.vnf = vnf;
	}
}

@XmlType
class Total{
	private ICMSTot valor;
	
	@XmlElement(name="ICMSTot",nillable=false,required=true)
	public ICMSTot getValor() {
		return valor;
	}

	public void setValor(ICMSTot valor) {
		this.valor = valor;
	}
}


@XmlRootElement(name="nfeProc")
class NfeProc{
	private NFe pkgnota;
	private String xmlns;
	
	@XmlElement(name="NFe",nillable=false,required=true)
	public NFe getPkgnota() {
		return pkgnota;
	}

	public void setPkgnota(NFe pkgnota) {
		this.pkgnota = pkgnota;
	}

	@XmlAttribute(name="xmlns",required=false)
	public String getXmlns() {
		return xmlns;
	}

	public void setXmlns(String xmlns) {
		this.xmlns = xmlns;
	}
}

@XmlType
class NFe{
	private NF notaemsi;
	
	@XmlElement(name="infNFe",nillable=false,required=true)
	public NF getNotaemsi() {
		return notaemsi;
	}

	public void setNotaemsi(NF notaemsi) {
		this.notaemsi = notaemsi;
	}
	
}

@XmlType
public class NF {
	private String id;
	private String versao;
	private Ide ide;
	private Dest dest;
	private List<Det> det=new ArrayList<Det>();
	private Total total;
	private Transp transp;
	
	@XmlAttribute(name="versao")
	public String getVersao(){
		return versao;
	}
	public void setVersao(String v){
		versao=v;
	}
	
	@XmlAttribute(name="Id",required=true)
	public String getId(){return id;}
	public void setId(String numb){id=numb;}
	
	@XmlElement(name="ide",nillable=false,required=true)
	public Ide getIde(){return ide;}
	public void setIde(Ide ids){ide=ids;}
	
	@XmlElement(name="dest", nillable=false,required=true)
	public Dest getDest() {return dest;}
	public void setDest(Dest dest) {this.dest = dest;}
	
	@XmlElement(name="det",type=Det.class,nillable=false,required=true)
	public List<Det> getDet() {return det;}
	public void setDet(List<Det> det) {this.det = det;}
	
	@XmlElement(name="total",nillable=false,required=true)
	public Total getTotal() {return total;}
	public void setTotal(Total total) {this.total = total;}
	
	@XmlElement(name="transp",nillable=false,required=true)
	public Transp getTransp() {return transp;}
	public void setTransp(Transp transp) {this.transp = transp;}
	
	public HashMap<String, Integer> contarProdutos(){
		HashMap<String, Integer> ret=new HashMap<String,Integer>();
		Iterator<Det> it=det.iterator();
		Det x;
		while(it.hasNext()){
			x=it.next();
			if(ret.containsKey(x.getProd().getcProd())){
				Integer k=ret.get(x.getProd().getcProd());
				k++;
				ret.put(x.getProd().getcProd(), k);
			}
			else{
				ret.put(x.getProd().getcProd(), new Integer(1));
			}
		}
		return ret;
	}
	
}
